package com.hopu.bean.time;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

import java.io.Serializable;
import java.util.Objects;

@Data
@AllArgsConstructor
@NoArgsConstructor
@ToString
public class TimeTop3Cate implements Serializable, Comparable<TimeTop3Cate>{

    private String hour;
    private String type;
    private String cid;
    private String cname;
    private int viewCount;
    private int cartCount;
    private int parchaseCount;

    public TimeTop3Cate(String hour, String type, String cid, String cname) {
        this.hour = hour;
        this.type = type;
        this.cid = cid;
        this.cname = cname;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        TimeTop3Cate top3Cate = (TimeTop3Cate) o;
        return Objects.equals(hour, top3Cate.hour) &&
                Objects.equals(cid, top3Cate.cid);
    }

    @Override
    public int hashCode() {
        return Objects.hash(hour, cid);
    }

    @Override
    public int compareTo(TimeTop3Cate o) {
        if (o.getViewCount() == this.getViewCount()) {
            if (o.getCartCount() == this.getCartCount()) {
                return o.getParchaseCount() - this.getParchaseCount();
            } else {
                return o.getCartCount() - this.getCartCount();
            }
        } else {
            return o.getViewCount() - this.getViewCount();
        }
    }
}
